package com.IceCreamQAQ.test.service.impl;

import act.Act;
import act.db.sql.tx.Transactional;
import com.IceCreamQAQ.test.dao.UserDao;
import com.IceCreamQAQ.test.entity.User;
import com.IceCreamQAQ.test.service.UserService;

import javax.inject.Inject;

public class UserServiceImpl implements UserService {

    @Inject
    private UserDao dao;

    @Override
    @Transactional
    public int register(User user) {
        dao.save(user);
        return 0;
    }

    @Override
    @Transactional
    public User login(Integer id, String password) {
        User user=dao.findById(id);
        if (Act.crypto().verifyPassword(password, user.password)) return user;
        else return null;
    }
}
